package com.evendai.sipdemo

import com.evendai.sipdemo.util.StorageUtil

/** 持久化变量，会保存到配置文件中，也可当全局变量使用 */
object PersistentVariables {

    var sipMessage: String = ""
        get() {
            if (field.isBlank()) {
                field = StorageUtil.getString(Keys.SIP_MESSAGE, "{\"action\":\"uploadLog\",\"type\":\"all\"}")
            }
            return field
        }
        set(value) {
            field = value
            StorageUtil.putString(Keys.SIP_MESSAGE, value)
        }

    var outgoingNumber = ""
        get() {
            if (field.isBlank()) {
                field = StorageUtil.getString(Keys.OUTGOING_NUMBER, "150202")
            }
            return field
        }
        set(value) {
            field = value
            StorageUtil.putString(Keys.OUTGOING_NUMBER, value)
        }

    /** sip服务器地址 */
    var sipIp: String = ""
        get() {
            if (field.isBlank()) {
                field = StorageUtil.getString(Keys.SIP_IP, "192.168.1.240")
            }
            return field
        }
        set(value) {
            field = value
            StorageUtil.putString(Keys.SIP_IP, value)
        }

    var isLogout: Boolean = false

    /** sip服务器端口 */
    var sipPort: Int = -1
        get() {
            if (field == -1) {
                field = StorageUtil.getInt(Keys.SIP_PORT, 5060)
            }
            return field
        }
        set(value) {
            field = value
            StorageUtil.putInt(Keys.SIP_PORT, value)
        }

    /** 传输协议 */
    var transport: String = ""
        get() {
            if (field.isBlank()) {
                field = StorageUtil.getString(Keys.SIP_TRANSPORT, "TCP")
            }
            return field
        }
        set(value) {
            field = value
            StorageUtil.putString(Keys.SIP_TRANSPORT, value)
        }

    /** 显示昵称 */
    var displayName: String = ""
        get() {
            if (field.isBlank()) {
                field = StorageUtil.getString(Keys.DISPLAY_NAME, "")
            }
            return field
        }
        set(value) {
            field = value
            StorageUtil.putString(Keys.DISPLAY_NAME, value)
        }
    /** sip账号 */
    var sipAccount: String = ""
        get() {
            if (field.isBlank()) {
                field = StorageUtil.getString(Keys.ACCOUNT, "")
            }
            return field
        }
        set(value) {
            field = value
            StorageUtil.putString(Keys.ACCOUNT, value)
        }

    /** sip密码 */
    var sipPassword: String = ""
        get() {
            if (field.isBlank()) {
                field = StorageUtil.getString(Keys.PASSWORD, "123")
            }
            return field
        }
        set(value) {
            field = value
            StorageUtil.putString(Keys.PASSWORD, value)
        }

    /** 语音会议号 */
    var audioMeetingNumber = ""
        get() {
            if (field.isBlank()) {
                field = StorageUtil.getString(Keys.AUDIO_MEETING_NUMBER, "")
            }
            return field
        }
        set(value) {
            field = value
            StorageUtil.putString(Keys.AUDIO_MEETING_NUMBER, value)
        }

    /** 视频会议号 */
    var videoMeetingNumber = ""
        get() {
            if (field.isBlank()) {
                field = StorageUtil.getString(Keys.VIDEO_MEETING_NUMBER, "")
            }
            return field
        }
        set(value) {
            field = value
            StorageUtil.putString(Keys.VIDEO_MEETING_NUMBER, value)
        }

    /** 语音会议前缀 */
    var audioMeetingPrefix = ""
        get() {
            if (field.isBlank()) {
                field = StorageUtil.getString(Keys.AUDIO_MEETING_PREFIX, Constants.pttmeeting)
            }
            return field
        }
        set(value) {
            field = value
            StorageUtil.putString(Keys.AUDIO_MEETING_PREFIX, value)
        }

    /** 非主摄像头视频会议前缀 */
    var videoMeetingPrefix = ""
        get() {
            if (field.isBlank()) {
                field = StorageUtil.getString(Keys.VIDEO_MEETING_PREFIX, Constants.pttmonitor)
            }
            return field
        }
        set(value) {
            field = value
            StorageUtil.putString(Keys.VIDEO_MEETING_PREFIX, value)
        }

    /** 主摄像头视频会议前缀 */
    var mainVideoMeetingPrefix = ""
        get() {
            if (field.isBlank()) {
                field = StorageUtil.getString(Keys.MAIN_VIDEO_MEETING_PREFIX, Constants.pttcameras)
            }
            return field
        }
        set(value) {
            field = value
            StorageUtil.putString(Keys.MAIN_VIDEO_MEETING_PREFIX, value)
        }

}